package org.distributed.transaction.core.propagation;

import org.distributed.transaction.core.annotion.PropagationStatus;
import org.distributed.transaction.core.context.TransactionContext;
import org.distributed.transaction.core.enums.Propagation;
import org.springframework.stereotype.Component;

/**
 * 默认事务传播解析器
 *
 */
@Component
public class DefaultPropagationResolver implements PropagationResolver {

	@Override
	public PropagationStatus resolvePropagation(Propagation propagation) {
		TransactionContext transactionContext = TransactionContext.get();
		if (transactionContext.isTransactionStart()) {
			// 事务发起者
			if (Propagation.SUPPORTS.equals(propagation)) {
				return PropagationStatus.NON;
			}
			return PropagationStatus.CREATE;
		}
		// 事务参与者，只能加入事务，不能创建事务
		return PropagationStatus.JOIN;
	}

}
